{% extends 'base.html' %}

{% block content %}
<div class="jumbotron mt-4">
    <h1 class="display-4">欢迎来到宋翱翔的博客</h1>
    <p class="lead">这里有技术分享、电影推荐、音乐推荐等精彩内容</p>
    <hr class="my-4">
    {% if current_user.is_authenticated %}
        <a class="btn btn-primary btn-lg" href="{{ url_for('new_post') }}" role="button">开始写作</a>
    {% else %}
        <a class="btn btn-primary btn-lg" href="{{ url_for('register') }}" role="button">立即注册</a>
    {% endif %}
</div>

<div class="row">
    <div class="col-md-8">
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h3>电影推荐</h3>
            <a href="{{ url_for('movies') }}" class="btn btn-outline-primary">查看全部</a>
        </div>
        <div class="row">
            {% for movie in movies %}
            <div class="col-md-4 mb-4">
                <div class="card h-100">
                    <div class="card-body">
                        <h5 class="card-title text-truncate" title="{{ movie.title }}">{{ movie.title }}</h5>
                        <p class="card-text">
                            <small class="text-muted">{{ movie.year }}</small>
                        </p>
                        <div class="btn-group">
                            <a href="https://www.kkys02.com/search?os=pc&k={{ movie.title }}" 
                               class="btn btn-sm btn-primary" target="_blank">观看</a>
                            {% if current_user.is_authenticated %}
                            <a href="{{ url_for('edit', movie_id=movie.id) }}" 
                               class="btn btn-sm btn-secondary">编辑</a>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h3>最新博客</h3>
            <a href="{{ url_for('blog') }}" class="btn btn-outline-primary">更多</a>
        </div>
        {% for post in recent_posts %}
        <div class="card mb-3">
            <div class="card-body">
                <h5 class="card-title">
                    <a href="{{ url_for('post', post_id=post.id) }}" class="text-decoration-none">{{ post.title }}</a>
                </h5>
                <p class="card-text">
                    <small class="text-muted">
                        {{ post.created_at.strftime('%Y-%m-%d') }} | {{ post.category }}
                    </small>
                </p>
            </div>
        </div>
        {% endfor %}
    </div>
</div>
{% endblock %}